package com.xhs.main.controller.scgl;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xhs.main.entity.scgl.*;
import com.xhs.main.service.scgl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sound.midi.Soundbank;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class scglController {

    @Autowired
    ScglScjhService scglScjhService;
    @Autowired
    ScglScjhmxService scglScjhmxService;
    @Autowired
    ScglWzxqjhService scglWzxqjhService;
    @Autowired
    ScglScrwService scglScrwService;
    @Autowired
    ScglRehbRyztService scglRehbRyztService;
    @Autowired
    ScglRehbScztService scglRehbScztService;
    @Autowired
    ScglRwhbService scglRwhbService;


    //生产计划============================================================================================================
    //异步请求,查询数据库中的信息(生产计划明细)(自定义Jackson方式实现异步)
    @ResponseBody
    @RequestMapping("/scgl_scjhmxselect")
    public void scgl_scjhmxcontroller(HttpServletRequest req, HttpServletResponse res) throws IOException {
        List<ScglScjhmx> scglScjhmxes = scglScjhmxService.scgl_scglScjhmx_selectAll();
        ObjectMapper obm = new ObjectMapper();
        obm.writeValue(res.getOutputStream(), scglScjhmxes);
    }

    @ResponseBody
    @RequestMapping("/scgl_scjhInsertSess")//存了一个session
    public void scgl_scjhInsertSess(HttpServletRequest req, HttpServletResponse res) throws IOException{
      String  scgl_xuanzhe  = req.getParameter("scgl_xuanzhe");
            HttpSession session=req.getSession();
            session.setAttribute("scgl_xuanzhe",scgl_xuanzhe);
    }


    @ResponseBody
    @RequestMapping("/scgl_scjhSelectThisDo")
    public Map<String, Object> scgl_scjhSelectThisDo(HttpServletRequest req, HttpServletResponse res) throws IOException{
        List<ScglScjh>   scglScjhs =scglScjhService.scgl_scglScjh_selectAll_thisDoing()  ;
        Map<String, Object> map = new HashMap<>();
        map.put("scglScjhs",scglScjhs);
        return map;
    }


    @ResponseBody
    @RequestMapping("/scgl_scjhSelect_passAndwzBang")////查询所有计划:审核通过,并且绑定了物资需求
    public Map<String, Object> scgl_scjhSelect_passAndwzBang(HttpServletRequest req, HttpServletResponse res) throws IOException{
        List<ScglScjh>   scglScjhs =scglScjhService.select_all_pass_and_wzxqjhBnag()  ;
        Map<String, Object> map = new HashMap<>();
        map.put("scglScjhs",scglScjhs);
        return map;
    }

    @ResponseBody
    @RequestMapping("/scgl_scjhSelect_passAndwzBang_andnoscjh")////查询所有计划:审核通过,并且绑定了物资需求和日生产计划
    public Map<String, Object> scgl_scjhSelect_passAndwzBang_andnoscjh(HttpServletRequest req, HttpServletResponse res) throws IOException{
        List<ScglScjh>   scglScjhs =scglScjhService.select_all_pass_and_wzxqjhBnag_andScjhBang()  ;
        Map<String, Object> map = new HashMap<>();
        map.put("scglScjhs",scglScjhs);
        return map;
    }


    @ResponseBody
    @RequestMapping("/scgl_scjhListselect")//查询所有生产计划
    public List<ScglScjh> scgl_scjhListcontroller(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        List<ScglScjh> scglScjhs = scglScjhService.scgl_scglScjh_selectAll();
        return scglScjhs;
    }

    @ResponseBody
    @RequestMapping("/scgl_scjhListselect_byLimit")//查询所有分页(生产计划)
    public Map<String, Object> scgl_scjhListselect_byLimit(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        Integer pageN = Integer.parseInt(req.getParameter("pageN"));
        Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));
        List<ScglScjh> scglScjhs = scglScjhService.scgl_scglScjh_selectAll_bylimit(thispageN, pageN);
        Map<String, Object> map = new HashMap<>();
        int allpage = 0;
        if (scglScjhService.scgl_scglScjh_selectAll().size() % pageN == 0) {
            allpage = scglScjhService.scgl_scglScjh_selectAll().size() / pageN;
        } else {
            allpage = (scglScjhService.scgl_scglScjh_selectAll().size() / pageN) + 1;
        }
        map.put("scglScjhs", scglScjhs);
        map.put("allpage", allpage);
        map.put("thispageN", thispageN);
        map.put("pageN", pageN);
        return map;
    }

    @ResponseBody
    @RequestMapping("/scgl_LikescjhListselect_byLimit")//模糊查询所有分页(生产计划)
    public Map<String, Object> scgl_LikescjhListselect_byLimit(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        Integer pageN = Integer.parseInt(req.getParameter("pageN"));
        Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));
        String scgl_scjh_personInCharge = req.getParameter("scgl_scjh_personInCharge");
        String scgl_scjh_project = req.getParameter("scgl_scjh_project");
        String scgl_scjh_status = req.getParameter("scgl_scjh_status");
        String scgl_scjh_billsStatus = req.getParameter("scgl_scjh_billsStatus");
        String scgl_scjh_documentNum = req.getParameter("scgl_scjh_documentNum");
        Integer scgl_scjh_statusInt = 0;
        Integer scgl_scjh_billsStatusInt = 0;
        Integer allConut = 0;
        int allpage = 0;
        List<ScglScjh> scglScjhs = new ArrayList<>();
        if (scgl_scjh_status != "" && scgl_scjh_billsStatus != "") {
            if (scgl_scjh_status.equals("已审批") ) {
                scgl_scjh_statusInt = 2;
            }
            if (scgl_scjh_status.equals("未审批")) {
                scgl_scjh_statusInt = 1;
            }
            if (scgl_scjh_billsStatus.equals("正在执行")) {
                scgl_scjh_billsStatusInt = 2;
            }
            if (scgl_scjh_billsStatus.equals("未执行")) {
                scgl_scjh_billsStatusInt = 1;
            }
            if (scgl_scjh_billsStatus.equals("已执行")) {
                scgl_scjh_billsStatusInt = 3;
            }
            scglScjhs = scglScjhService.scgl_scglScjh_LikeselectAll_bylimit(scgl_scjh_documentNum, scgl_scjh_personInCharge, scgl_scjh_project,
                    scgl_scjh_statusInt, scgl_scjh_billsStatusInt, thispageN, pageN);
            allConut = scglScjhService.scgl_scglScjh_LikeselectAll(scgl_scjh_documentNum, scgl_scjh_personInCharge, scgl_scjh_project,
                    scgl_scjh_statusInt, scgl_scjh_billsStatusInt).size();
        }
        if (scgl_scjh_status != "" && scgl_scjh_billsStatus == "") {
            if (scgl_scjh_status.equals("已审批") ) {
                scgl_scjh_statusInt = 2;
            }
            if (scgl_scjh_status.equals("未审批")) {
                scgl_scjh_statusInt = 1;
            }
            scglScjhs = scglScjhService.scgl_scglScjh_LikeselectAll_bylimit(scgl_scjh_documentNum, scgl_scjh_personInCharge, scgl_scjh_project,
                    scgl_scjh_statusInt, null, thispageN, pageN);
            allConut = scglScjhService.scgl_scglScjh_LikeselectAll(scgl_scjh_documentNum, scgl_scjh_personInCharge, scgl_scjh_project,
                    scgl_scjh_statusInt, null).size();

        }

        if (scgl_scjh_status == "" && scgl_scjh_billsStatus != "") {
            if (scgl_scjh_billsStatus.equals("正在执行")) {
                scgl_scjh_billsStatusInt = 2;
            }
            if (scgl_scjh_billsStatus.equals("未执行")) {
                scgl_scjh_billsStatusInt = 1;
            }
            if (scgl_scjh_billsStatus.equals("已执行")) {
                scgl_scjh_billsStatusInt = 3;
            }
            scglScjhs = scglScjhService.scgl_scglScjh_LikeselectAll_bylimit(scgl_scjh_documentNum, scgl_scjh_personInCharge, scgl_scjh_project,
                    null, scgl_scjh_billsStatusInt, thispageN, pageN);
            allConut = scglScjhService.scgl_scglScjh_LikeselectAll(scgl_scjh_documentNum, scgl_scjh_personInCharge, scgl_scjh_project,
                    null, scgl_scjh_billsStatusInt).size();


        }
        if (scgl_scjh_status == "" && scgl_scjh_billsStatus == "") {
            scglScjhs = scglScjhService.scgl_scglScjh_LikeselectAll_bylimit(scgl_scjh_documentNum, scgl_scjh_personInCharge, scgl_scjh_project,
                    null, null, thispageN, pageN);

            allConut = scglScjhService.scgl_scglScjh_LikeselectAll(scgl_scjh_documentNum, scgl_scjh_personInCharge, scgl_scjh_project,
                    null, null).size();
        }

        if (scgl_scjh_status == "" && scgl_scjh_billsStatus == "" && scgl_scjh_personInCharge == ""
                && scgl_scjh_project == "" && scgl_scjh_documentNum == "") {
            scglScjhs = scglScjhService.scgl_scglScjh_selectAll_bylimit(thispageN, pageN);
            allConut = scglScjhService.scgl_scglScjh_selectAll().size();
        }
        Map<String, Object> map = new HashMap<>();
        if (allConut % pageN == 0) {
            allpage = allConut / pageN;
        } else {
            allpage = (allConut / pageN) + 1;
        }
        map.put("scglScjhs", scglScjhs);
        map.put("allpage", allpage);
        map.put("thispageN", thispageN);
        map.put("pageN", pageN);
       return map;
    }


    @ResponseBody
    @RequestMapping("/scgl_scjhselectOne")//查询单个(生产计划)
    public ScglScjh scgl_scjhselectOne(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        String scglScjhDocumentnum = req.getParameter("scglScjhDocumentnum");
        ScglScjh scglScjh = scglScjhService.scgl_scglScjh_selectOne(scglScjhDocumentnum);
        return scglScjh;
    }


    //订单===================================================================================================
    @ResponseBody
    @RequestMapping("/scgl_scjhmxselectAll_limit")//分页查询所有(生产订单)
    public Map<String, Object> scgl_scjhmxselectAll(HttpServletRequest req, HttpServletResponse res) {
        Integer pageN = Integer.parseInt(req.getParameter("pageN"));
        Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));
        List<ScglScjhmx> scglScjhmxes = scglScjhmxService.scgl_scglScjhmx_selectAll_bylimit(thispageN, pageN);
        Map<String, Object> map = new HashMap<>();
        int allpage = 0;
        if (scglScjhmxService.scgl_scglScjhmx_selectAll().size() % pageN == 0) {
            allpage = scglScjhmxService.scgl_scglScjhmx_selectAll().size() / pageN;
        } else {
            allpage = (scglScjhmxService.scgl_scglScjhmx_selectAll().size() / pageN) + 1;
        }
        map.put("scglScjhmxes", scglScjhmxes);
        map.put("allpage", allpage);
        map.put("thispageN", thispageN);
        map.put("pageN", pageN);
        return map;
    }

    @ResponseBody
    @RequestMapping("/scgl_scjhmxselectOne")//查询单个(订单)
    public ScglScjhmx scgl_scjhmxselectOne(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        String scglScjhDocumentnum = req.getParameter("scglScjhDocumentnum");
        ScglScjhmx scglScjhmx=scglScjhmxService.scgl_scglScjhmx_selectOne_byscjhDan(scglScjhDocumentnum);
        return scglScjhmx;
    }



    @ResponseBody
    @RequestMapping("/scgl_scjhmxselectAll_noBnag_limit")//查询所有(没被绑定的生产订单)
    public void scgl_scjhmxselectAll_noBnag_limit(HttpServletRequest req, HttpServletResponse res)throws IOException {
        List<ScglScjhmx> scglScjhmxes = scglScjhmxService.scgl_scglScjhmx_noBang();
        ObjectMapper obm = new ObjectMapper();
        obm.writeValue(res.getOutputStream(), scglScjhmxes);

    }


    //模糊查询生产订单
    @ResponseBody
    @RequestMapping("/scgl_LikescjhmxselectAll_limit")//模糊查询所有(生产订单)
    public Map<String, Object> scgl_LikescjhmxselectAll_limit(HttpServletRequest req, HttpServletResponse res){
        String scgl_scjhmx_itemName=req.getParameter("scgl_scjhmx_itemName");
        String scgl_scjhmx_startDate=req.getParameter("scgl_scjhmx_startDate");
        String scgl_scjhmx_overDate=req.getParameter("scgl_scjhmx_overDate");
        Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));
        Integer pageN = Integer.parseInt(req.getParameter("pageN"));
        int allpage = 0;
        Integer allcount=0;
        List<ScglScjhmx> scglScjhmxes =scglScjhmxService.scgl_scglScjhmx_LikeselectAll_bylimit(scgl_scjhmx_itemName,scgl_scjhmx_startDate,scgl_scjhmx_overDate,thispageN,pageN);
        Map<String, Object> map = new HashMap<>();
        allcount=scglScjhmxService.scgl_scglScjhmx_LikeselectAll(scgl_scjhmx_itemName,scgl_scjhmx_startDate,scgl_scjhmx_overDate).size();
        if (allcount% pageN == 0) {
            allpage = allcount / pageN;
        } else {
            allpage = (allcount / pageN) + 1;
        }
        map.put("scglScjhmxes", scglScjhmxes);
        map.put("allpage", allpage);
        map.put("thispageN", thispageN);
        map.put("pageN", pageN);
        return map;


    }

//物资=================================================================================================
@ResponseBody
@RequestMapping("/scgl_wzxqjhListselect_byLimit")//查询所有分页(物资需求)
    public Map<String, Object> scgl_wzxqjhListselect_byLimit(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
    Integer pageN = Integer.parseInt(req.getParameter("pageN"));
    Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));
    List<ScglWzxqjh> scglWzxqjhs = scglWzxqjhService.scgl_Wzxqjh_selectAll_bylimit(thispageN, pageN);
    Map<String, Object> map = new HashMap<>();
    int allpage = 0;
    if (scglWzxqjhService.scgl_scglWzxqjh_selectAll().size() % pageN == 0) {
        allpage = scglWzxqjhService.scgl_scglWzxqjh_selectAll().size() / pageN;
    } else {
        allpage = (scglWzxqjhService.scgl_scglWzxqjh_selectAll().size() / pageN) + 1;
    }
    map.put("scglWzxqjhs", scglWzxqjhs);
    map.put("allpage", allpage);
    map.put("thispageN", thispageN);
    map.put("pageN", pageN);
    return map;
}


    @ResponseBody
    @RequestMapping("/scgl_LikewzxqjhListselect_byLimit")//模糊查询所有分页(物资需求)
    public Map<String, Object> scgl_LikewzxqjhListselect_byLimit(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        Integer pageN = Integer.parseInt(req.getParameter("pageN"));
        Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));

        String scgl_wzxqjh_personInCharge = req.getParameter("scgl_wzxqjh_personInCharge");
        String scgl_wzxqjh_mpp_id = req.getParameter("scgl_wzxqjh_mpp_id");
        String scgl_wzxqjh_status = req.getParameter("scgl_wzxqjh_status");
        String scgl_wzxqjh_billsStatus = req.getParameter("scgl_wzxqjh_billsStatus");
        String scgl_wzxqjh_documentNum = req.getParameter("scgl_wzxqjh_documentNum");

        Integer scgl_scjh_statusInt = 0;
        Integer scgl_scjh_billsStatusInt = 0;
        Integer allConut = 0;
        int allpage = 0;
        List<ScglWzxqjh> scglWzxqjhs = new ArrayList<>();
        if (scgl_wzxqjh_status != "" && scgl_wzxqjh_status != "") {
            if (scgl_wzxqjh_status.equals("已审批") ) {
                scgl_scjh_statusInt = 2;
            }
            if (scgl_wzxqjh_status.equals("未审批")) {
                scgl_scjh_statusInt = 1;
            }
            if (scgl_wzxqjh_billsStatus.equals("正在执行")) {
                scgl_scjh_billsStatusInt = 2;
            }
            if (scgl_wzxqjh_billsStatus.equals("未执行")) {
                scgl_scjh_billsStatusInt = 1;
            }
            if (scgl_wzxqjh_billsStatus.equals("已执行")) {
                scgl_scjh_billsStatusInt = 3;
            }
             scglWzxqjhs = scglWzxqjhService.scgl_Wzxqjh_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge,
                    scgl_wzxqjh_mpp_id, scgl_scjh_statusInt, scgl_scjh_billsStatusInt, thispageN, pageN);
            allConut = scglWzxqjhService.scgl_Wzxqjh_LikeselectAll(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge,
                    scgl_wzxqjh_mpp_id, scgl_scjh_statusInt, scgl_scjh_billsStatusInt).size();
        }
        if (scgl_wzxqjh_status != "" && scgl_wzxqjh_billsStatus == "") {
            if (scgl_wzxqjh_status.equals("已审批") ) {
                scgl_scjh_statusInt = 2;
            }
            if (scgl_wzxqjh_status.equals("未审批")) {
                scgl_scjh_statusInt = 1;
            }
             scglWzxqjhs = scglWzxqjhService.scgl_Wzxqjh_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,
                    scgl_scjh_statusInt, null, thispageN, pageN);
            allConut = scglWzxqjhService.scgl_Wzxqjh_LikeselectAll(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,
                    scgl_scjh_statusInt, null).size();

        }

        if (scgl_wzxqjh_status == "" && scgl_wzxqjh_billsStatus != "") {
            if (scgl_wzxqjh_billsStatus.equals("正在执行")) {
                scgl_scjh_billsStatusInt = 2;
            }
            if (scgl_wzxqjh_billsStatus.equals("未执行")) {
                scgl_scjh_billsStatusInt = 1;
            }
            if (scgl_wzxqjh_billsStatus.equals("已执行")) {
                scgl_scjh_billsStatusInt = 3;
            }

            scglWzxqjhs = scglWzxqjhService.scgl_Wzxqjh_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge,
                    scgl_wzxqjh_mpp_id, null, scgl_scjh_billsStatusInt, thispageN, pageN);
            allConut = scglWzxqjhService.scgl_Wzxqjh_LikeselectAll(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge,
                    scgl_wzxqjh_mpp_id, null, scgl_scjh_billsStatusInt).size();


        }
        if (scgl_wzxqjh_status == "" && scgl_wzxqjh_billsStatus == "") {
             scglWzxqjhs = scglWzxqjhService.scgl_Wzxqjh_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge,
                    scgl_wzxqjh_mpp_id, null, null, thispageN, pageN);
            allConut = scglWzxqjhService.scgl_Wzxqjh_LikeselectAll(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge,
                    scgl_wzxqjh_mpp_id, null, null).size();
        }

        if (scgl_wzxqjh_status == "" && scgl_wzxqjh_billsStatus == "" && scgl_wzxqjh_personInCharge == ""
                && scgl_wzxqjh_mpp_id == "" && scgl_wzxqjh_documentNum == "") {
            scglWzxqjhs= scglWzxqjhService.scgl_Wzxqjh_selectAll_bylimit(thispageN,pageN);
            allConut = scglWzxqjhService.scgl_scglWzxqjh_selectAll().size();
        }
        Map<String, Object> map = new HashMap<>();
        if (allConut % pageN == 0) {
            allpage = allConut / pageN;
        } else {
            allpage = (allConut / pageN) + 1;
        }
        map.put("scglWzxqjhs", scglWzxqjhs);
        map.put("allpage", allpage);
        map.put("thispageN", thispageN);
        map.put("pageN", pageN);
        return map;
    }

    @ResponseBody
    @RequestMapping("/scgl_wzxqjhselectOne")//查询单个(物资需求)
    public ScglWzxqjh scgl_wzxqjhselectOne(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        String scglWzxqjhDocumentnum = req.getParameter("scglWzxqjhDocumentnum");
        ScglWzxqjh scglWzxqjh = scglWzxqjhService.scgl_scglWzxqjh_selectOne(scglWzxqjhDocumentnum);
        System.out.println(scglWzxqjh);
        return scglWzxqjh;
    }


//日生产计划===============================================================================================
    @ResponseBody
    @RequestMapping("/scgl_scrwListselect_byLimit")//查询所有分页(日生产计划)
    public Map<String, Object> scgl_scrwListselect_byLimit(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
    Integer pageN = Integer.parseInt(req.getParameter("pageN"));
    Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));
    List<ScglScrw> scglScrws =scglScrwService.scgl_scglScrw_selectAll_bylimit(thispageN,pageN);
    Map<String, Object> map = new HashMap<>();
    int allpage = 0;
    if (scglScrwService.scgl_scglScrw_selectAll().size() % pageN == 0) {
        allpage = scglScrwService.scgl_scglScrw_selectAll().size() / pageN;
    } else {
        allpage = (scglScrwService.scgl_scglScrw_selectAll().size() / pageN) + 1;
    }
    map.put("scglScrws", scglScrws);
    map.put("allpage", allpage);
    map.put("thispageN", thispageN);
    map.put("pageN", pageN);
    return map;
}

    @ResponseBody
    @RequestMapping("/scgl_LikescrwListselect_byLimit")//模糊查询所有分页(日生产计划)
    public Map<String, Object> scgl_LikescrwListselect_byLimit(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        Integer pageN = Integer.parseInt(req.getParameter("pageN"));
        Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));

        String scgl_wzxqjh_personInCharge = req.getParameter("scgl_wzxqjh_personInCharge");
        String scgl_wzxqjh_mpp_id = req.getParameter("scgl_wzxqjh_mpp_id");
        String scgl_wzxqjh_status = req.getParameter("scgl_wzxqjh_status");
        String scgl_wzxqjh_billsStatus = req.getParameter("scgl_wzxqjh_billsStatus");
        String scgl_wzxqjh_documentNum = req.getParameter("scgl_wzxqjh_documentNum");
        String scgl_scrw_machiningType = req.getParameter("scgl_scrw_machiningType");

        Integer scgl_scjh_statusInt = 0;
        Integer scgl_scjh_billsStatusInt = 0;
        Integer allConut = 0;
        int allpage = 0;
        List<ScglScrw> scglScrws = new ArrayList<>();
        if (scgl_wzxqjh_status != "" && scgl_wzxqjh_status != "") {
            if (scgl_wzxqjh_status.equals("已审批") ) {
                scgl_scjh_statusInt = 2;
            }
            if (scgl_wzxqjh_status.equals("未审批")) {
                scgl_scjh_statusInt = 1;
            }
            if (scgl_wzxqjh_billsStatus.equals("正在执行")) {
                scgl_scjh_billsStatusInt = 2;
            }
            if (scgl_wzxqjh_billsStatus.equals("未执行")) {
                scgl_scjh_billsStatusInt = 1;
            }
            if (scgl_wzxqjh_billsStatus.equals("已执行")) {
                scgl_scjh_billsStatusInt = 3;
            }
            scglScrws = scglScrwService.scgl_scglScrw_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,
                    scgl_scrw_machiningType ,scgl_scjh_statusInt, scgl_scjh_billsStatusInt, thispageN, pageN);
            allConut = scglScrwService.scgl_scglScrw_LikeselectAll(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,scgl_scrw_machiningType,
                    scgl_scjh_statusInt, scgl_scjh_billsStatusInt).size();

        }
        if (scgl_wzxqjh_status != "" && scgl_wzxqjh_billsStatus == "") {
            if (scgl_wzxqjh_status.equals("已审批") ) {
                scgl_scjh_statusInt = 2;
            }
            if (scgl_wzxqjh_status.equals("未审批")) {
                scgl_scjh_statusInt = 1;
            }
            scglScrws = scglScrwService.scgl_scglScrw_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,
                    scgl_scrw_machiningType ,scgl_scjh_statusInt, null, thispageN, pageN);
            allConut = scglScrwService.scgl_scglScrw_LikeselectAll(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,scgl_scrw_machiningType,
                    scgl_scjh_statusInt, null).size();

        }

        if (scgl_wzxqjh_status == "" && scgl_wzxqjh_billsStatus != "") {
            if (scgl_wzxqjh_billsStatus.equals("正在执行")) {
                scgl_scjh_billsStatusInt = 2;
            }
            if (scgl_wzxqjh_billsStatus.equals("未执行")) {
                scgl_scjh_billsStatusInt = 1;
            }
            if (scgl_wzxqjh_billsStatus.equals("已执行")) {
                scgl_scjh_billsStatusInt = 3;
            }


            scglScrws = scglScrwService.scgl_scglScrw_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,
                    scgl_scrw_machiningType ,null, scgl_scjh_billsStatusInt, thispageN, pageN);
            allConut = scglScrwService.scgl_scglScrw_LikeselectAll(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,scgl_scrw_machiningType,
                    null, scgl_scjh_billsStatusInt).size();

        }
        if (scgl_wzxqjh_status == "" && scgl_wzxqjh_billsStatus == "") {


            scglScrws = scglScrwService.scgl_scglScrw_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,
                    scgl_scrw_machiningType ,null, null, thispageN, pageN);
            allConut = scglScrwService.scgl_scglScrw_LikeselectAll(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,scgl_scrw_machiningType,
                    null, null).size();


        }

        if (scgl_wzxqjh_status == "" && scgl_wzxqjh_billsStatus == "" && scgl_wzxqjh_personInCharge == ""
                && scgl_wzxqjh_mpp_id == "" && scgl_wzxqjh_documentNum == "") {

            scglScrws=scglScrwService.scgl_scglScrw_selectAll_bylimit(thispageN,pageN);

            allConut = scglScrwService.scgl_scglScrw_selectAll().size();
        }
        Map<String, Object> map = new HashMap<>();
        if (allConut % pageN == 0) {
            allpage = allConut / pageN;
        } else {
            allpage = (allConut / pageN) + 1;
        }
        map.put("scglScrws", scglScrws);
        map.put("allpage", allpage);
        map.put("thispageN", thispageN);
        map.put("pageN", pageN);
        return map;
    }

    @ResponseBody
    @RequestMapping("/scgl_scrwjhselectOne")//查询单个(日生产计划)
    public Map<String, Object> scgl_scrwjhselectOne(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        String scglWzxqjhDocumentnum = req.getParameter("scglWzxqjhDocumentnum");
        ScglScrw scglScrw = scglScrwService.scgl_scglScrw_selectOne(scglWzxqjhDocumentnum);
        Map<String, Object> map = new HashMap<>();
        map.put("scglScrw",scglScrw);
        return map;
    }

    @ResponseBody
    @RequestMapping("/scgl_scrwjhselectThiszhixing")//查询所有(日生产计划,状态为正在执行的)
    public Map<String, Object> scgl_scrwjhselectThiszhixing(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        List<ScglScrw> scglScrws = scglScrwService.scgl_scglScrw_selectAllThiszhixing();
        Map<String, Object> map = new HashMap<>();
       map.put("scglScrws",scglScrws);
        return map;
    }


    //任务汇报===============================================================================================

    @ResponseBody
    @RequestMapping("/scgl_rwhbListselect_byLimit")//查询所有分页(任务汇报)
    public Map<String, Object> scgl_rwhbListselect_byLimit(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        Integer pageN = Integer.parseInt(req.getParameter("pageN"));
        Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));
        List<ScglRwhb> scglRwhbs = scglRwhbService.scgl_scglRwhb_selectAll_bylimit(thispageN, pageN);
        Map<String, Object> map = new HashMap<>();
        int allpage = 0;
        if (scglRwhbService.scgl_scglRwhb_selectAll().size() % pageN == 0) {
            allpage = scglRwhbService.scgl_scglRwhb_selectAll().size() / pageN;
        } else {
            allpage = (scglRwhbService.scgl_scglRwhb_selectAll().size() / pageN) + 1;
        }
        map.put("scglRwhbs", scglRwhbs);
        map.put("allpage", allpage);
        map.put("thispageN", thispageN);
        map.put("pageN", pageN);
        return map;
    }

    @ResponseBody
    @RequestMapping("/scgl_LikerwhbListselect_byLimit")//模糊查询所有分页(任务汇报)
    public Map<String, Object> scgl_LikerwhbListselect_byLimit(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        Integer pageN = Integer.parseInt(req.getParameter("pageN"));
        Integer thispageN = Integer.parseInt(req.getParameter("thispageN"));
        List<ScglRwhb> scglRwhbs = new ArrayList<>();

        String scgl_wzxqjh_personInCharge = req.getParameter("scgl_wzxqjh_personInCharge");
        String scgl_wzxqjh_mpp_id = req.getParameter("scgl_wzxqjh_mpp_id");
        String scgl_wzxqjh_documentNum = req.getParameter("scgl_wzxqjh_documentNum");

        scglRwhbs = scglRwhbService.scgl_scglRwhb_LikeselectAll_bylimit(scgl_wzxqjh_documentNum, scgl_wzxqjh_personInCharge, scgl_wzxqjh_mpp_id,
                thispageN, pageN);
        Integer allConut =scglRwhbService.scgl_scglRwhb_LikeselectAll(scgl_wzxqjh_documentNum,scgl_wzxqjh_personInCharge,scgl_wzxqjh_mpp_id).size() ;

        int allpage = 0;


        if (scgl_wzxqjh_personInCharge == ""
                && scgl_wzxqjh_mpp_id == "" && scgl_wzxqjh_documentNum == "") {
            scglRwhbs=scglRwhbService.scgl_scglRwhb_selectAll();
            allConut = scglRwhbService.scgl_scglRwhb_selectAll().size();
        }
        Map<String, Object> map = new HashMap<>();
        if (allConut % pageN == 0) {
            allpage = allConut / pageN;
        } else {
            allpage = (allConut / pageN) + 1;
        }
        map.put("scglRwhbs", scglRwhbs);
        map.put("allpage", allpage);
        map.put("thispageN", thispageN);
        map.put("pageN", pageN);
        return map;
    }

    @ResponseBody
    @RequestMapping("/scgl_rwhbjhselectOne")//查询单个(任务汇报)
    public Map<String, Object> scgl_rwhbjhselectOne(HttpServletRequest req, HttpServletResponse res) throws JsonGenerationException, JsonMappingException, IOException {
        String scgl_rwhb_documentNum = req.getParameter("scgl_rwhb_documentNum");
        ScglRwhb scglRwhb = scglRwhbService.scgl_scglRwhb_selectOne(scgl_rwhb_documentNum);
        ScglRehbSczt scglRehbSczt = scglRehbScztService.scgl_RehbSczt_selectOne(scglRwhb.getScglRwhbId());
        ScglRehbRyzt scglRehbRyzt = scglRehbRyztService.scgl_rehbRyzt_selectOne(scglRwhb.getScglRwhbId());
        ScglScrw scglScrw = scglScrwService.scgl_scglScrw_selectOne(scglRwhb.getScglRwhbScjhDocumentnum());
        Map<String, Object> map = new HashMap<>();
        map.put("scglRwhb",scglRwhb);
        map.put("scglRehbSczt",scglRehbSczt);
        map.put("scglRehbRyzt",scglRehbRyzt);
        map.put("scglScrw",scglScrw);
        return map;
    }








}